package com.hyd.issues;

import com.hyd.dao.config.Config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.File;

/**
 * (description)
 *
 * @author yiding.he
 */
public class AppListener implements ServletContextListener {

    static final Log log = LogFactory.getLog(AppListener.class);

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        try {
            ServletContext context = servletContextEvent.getServletContext();

            AppConfiguration.setRootPath(context.getRealPath(""));
            Config.readConfig(new File(context.getRealPath("/WEB-INF/dao-config.xml")));
            
            log.debug("-- 应用初始化完毕 --");
        } catch (Exception e) {
            throw new AppException(e);
        }
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        log.debug("-- 应用被取消部署 --");
    }
}
